<?php

class saveEmploymentContractTypeAction extends sfAction
{

    public function setForm(sfForm $form)
    {
        if (is_null($this->form)) {
            $this->form = $form;
        }
    }

    public function execute($request)
    {

        /* For highlighting corresponding menu item */
        $request->setParameter('initialActionName', 'viewEmploymentContractTypeList');

        $usrObj = $this->getUser()->getAttribute('user');
        if (!($usrObj->isAdmin())) {
            $this->redirect('pim/viewPersonalDetails');
        }
        $this->getUser()->setAttribute('addScreen', true);
        $employmentContractTypeId = $request->getParameter('employmentContractTypeId');
        $values = array('employmentContractTypeId' => $employmentContractTypeId);

        $this->setForm(new EmploymentContractTypeForm(array(), $values));

        if ($request->isMethod('post')) {
            $this->form->bind($request->getParameter($this->form->getName()));

            if ($this->form->isValid()) {
                $result = $this->form->save();
                $this->getUser()->setFlash($result['messageType'], $result['message']);
                $this->redirect('tluadmin/viewEmploymentContractTypeList');
            }
        }
    }

}

